<?php
/**
 * Classe d'acces à la configuration de l'application
 * 
 * exemple d'utilisation
 * <code>
 * 		echo AppConfig::instance()->DB_HOST;
 * </code>
 * 
 * @version   1.0
 * @todo Gerer la configuation dans un fichier externe et le stocker en session pour eviter d'ouvrir a chaque page
* 
 **/
class AppConfig {
    private static $initialized = false;


	private static $instance;
	
	private $settings = array(
		'DEBUG' => true,
		'DB_HOST' => 'localhost',
	 	'DB_USER' => 'contact.tendero',
	  	'DB_PASS' => 'montagne',
	  	'DB_NAME' => 'contact_tendero',
	  	'SITE_URL' => 'http://contact.tendero.free.fr/blog/',
	  	'SITE_TITLE' => 'nou La di, nou la fé'
	);
	
	 
	public function __construct() {
		$this->initialize();
	}
	
    private function initialize() {
    	if (self::$initialized)
    		return;
		
		if ( $_SERVER['SERVER_NAME'] == '127.0.0.1'
			|| $_SERVER['SERVER_NAME'] == 'localhost')
		{
			$this->settings['DB_HOST'] = 'localhost';
		  	$this->settings['DB_USER'] = 'root';
		  	$this->settings['DB_PASS'] = '';
		  	$this->settings['DB_NAME'] = 'blog';
		  	$this->settings['SITE_URL'] = 'http://127.0.0.1/projects/trunk/';
		}


    	self::$initialized = true;
    }


	/**
	* @return AppConfig
	*/
	public static function getInstance() {
	if (!isset(self::$instance)) {
	  self::$instance = new self();
	}
	return self::$instance;
	}
	 
	public function __get($name) {
		if ($name == 'ALL')
			return $this->settings;
			
		if (!isset($this->settings[$name]))
   			throw new Exception('Unknown setting '.$name);
			
		return $this->settings[$name];
	}
	 
	public function __set($name, $value) {
		$this->settings[$name] = $value;
	}

	public function isDebug() {
		if (!isset($this->settings['DEBUG']))
   			return true;
			
		return $this->settings['DEBUG'];
	}
}

?>